﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Diablo3.Engine;
using Diablo3.Engine.Property;
using UtilityLibrary.Serialize;
using System.Xml;

namespace Diablo3.Window
{
    public partial class SimulatorWindow : Form
    {
        Classes _classes = null;
        Items _itemsA = null;
        Items _itemsB = null;
        Items _itemsC = null;

        public SimulatorWindow()
        {
            InitializeComponent();
            CreateNewClasses("Barbarian");
        }

        public void RefreshClassesData()
        {
            if (_classes is Barbarian)
            {
                lblClassesType.Text = "职业        野蛮人";
            }
            else if (_classes is Wizard)
            {
                lblClassesType.Text = "职业        秘术师";
            }
            else if (_classes is WitchDoctor)
            {
                lblClassesType.Text = "职业        巫医";
            }
            else if (_classes is Monk)
            {
                lblClassesType.Text = "职业        武僧";
            }
            else if (_classes is DemonHunter)
            {
                lblClassesType.Text = "职业        猎魔人";
            }
            lblClassesStrength.Text = String.Format("力量        {0}", _classes.Strength);
            lblClassesDexterity.Text = String.Format("敏捷        {0}", _classes.Dexterity);
            lblClassesIntelligence.Text = String.Format("智力        {0}", _classes.Intelligence);
            lblClassesVitality.Text = String.Format("体力        {0}", _classes.Vitality);
            lblClassesLife.Text = String.Format("生命值      {0}", _classes.Life.ToString("F0"));
            lblClassesArmor.Text = String.Format("护甲值      {0}", _classes.Armor);
            lblClassesDamageReductionByArmor.Text = String.Format("护甲减伤    {0}", _classes.DamageReductionByArmor.ToString("P"));
            lblClassesPhysicalResistance.Text = String.Format("物理抗性    {0}", _classes.PhysicalResistance.ToString("F0"));
            lblClassesColdResistance.Text = String.Format("寒冰抗性    {0}", _classes.ColdResistance.ToString("F0"));
            lblClassesFireResistance.Text = String.Format("火焰抗性    {0}", _classes.FireResistance.ToString("F0"));
            lblClassesLightningResistance.Text = String.Format("电击抗性    {0}", _classes.LightningResistance.ToString("F0"));
            lblClassesPoisonResistance.Text = String.Format("毒素抗性    {0}", _classes.PoisonResistance.ToString("F0"));
            lblClassesAranceHolyResistance.Text = String.Format("秘法抗性    {0}", _classes.ArcaneHolyResistance.ToString("F0"));
            lblClassesDamageReductionByRestance.Text = String.Format("抗性减伤    {0}", _classes.DamageReductionByResistance.ToString("P"));
            lblClassesDodgeChance.Text = String.Format("闪避几率    {0}", _classes.DodgeChance.ToString("P"));
            lblClassesMeleeDamageReduction.Text = String.Format("近战减伤    {0}", _classes.MeleeDamageReduction.ToString("P"));
            lblClassesMissileDamageReduction.Text = String.Format("远程减伤    {0}", _classes.MissileDamageReduction.ToString("P"));
            lblClassesTotalDamageReduction.Text = String.Format("总减伤      {0}", _classes.TotalDamageReduction.ToString("P"));
            lblClassesBlockValue.Text = String.Format("格挡值      {0}-{1}", _classes.MinBlockValue, _classes.MaxBlockValue);
            lblClassesBlockChance.Text = String.Format("格挡几率    {0}", _classes.BlockChance.ToString("P"));
            lblClassesEffectiveLife.Text = String.Format("有效生命值  {0}", _classes.EffectiveLife.ToString("F"));

            lblClassesDamageIncreasedByMainProperty.Text = String.Format("主属性加成  {0}", _classes.DamageIncreasedByMainProperty.ToString("P"));
            lblClassesDamageIncreasedBySkills.Text = String.Format("技能加成    {0}", _classes.DamageIncreasedBySkills.ToString("P"));
            lblClassesAttackSpeed.Text = String.Format("攻速        {0}", _classes.AttackSpeed.ToString("F2"));
            lblClassesCriticalHitChance.Text = String.Format("暴击几率    {0}", _classes.CriticalHitChance.ToString("P"));
            lblClassesCriticalHitDamage.Text = String.Format("暴击伤害    {0}", _classes.CriticalHitDamage.ToString("P"));
            lblClassesDamage.Text = String.Format("面板伤害    {0}", _classes.Damage.ToString("F2"));

            lblClassesLifePerHit.Text = String.Format("击中恢复    {0}", _classes.LifePerHit.ToString("F0"));
            lblClassesLifePerKill.Text = String.Format("击杀恢复    {0}", _classes.LifePerKill.ToString("F0"));
            lblClassesLifePerSecond.Text = String.Format("每秒恢复    {0}", _classes.LifePerSecond.ToString("F0"));
            lblClassesLifeSteal.Text = String.Format("生命汲取    {0}", _classes.LifeSteal.ToString("F0"));

            RefreshItemsAData();
            RefreshItemsBData();
            RefreshItemsCData();
        }

        private void items_MouseClick(object sender, MouseEventArgs e)
        {
            ItemsControl ctrl = sender as ItemsControl;
            if (ctrl != null)
            {
                if (ctrl.Items == null) return;

                SelectProperty selectWindow = new SelectProperty(ctrl.Items);
                if (selectWindow.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    ctrl.Items = selectWindow.Items;
                    ctrl.Refresh();
                    RefreshClassesData();
                }
            }
        }

        private void menuSave_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveDialog = new SaveFileDialog();
            saveDialog.Filter = "Xml文件(*.xml)|*.xml|所有文件(*.*)|*.*";
            if (saveDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(XmlSerializable.Serialization(_classes));
                doc.Save(saveDialog.FileName);
            }
        }

        private void menuImport_Click(object sender, EventArgs e)
        {
            OpenFileDialog openDialog = new OpenFileDialog();
            openDialog.Filter = "Xml文件(*.xml)|*.xml|所有文件(*.*)|*.*";
            if (openDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(openDialog.FileName);
                if (doc.InnerXml.Contains("</Barbarian>"))
                {
                    _classes = (Classes)XmlSerializable.Deserialization(doc.InnerXml, typeof(Barbarian));
                }
                else if (doc.InnerXml.Contains("</Wizard>"))
                {
                    _classes = (Classes)XmlSerializable.Deserialization(doc.InnerXml, typeof(Wizard));
                }
                else if (doc.InnerXml.Contains("</Monk>"))
                {
                    _classes = (Classes)XmlSerializable.Deserialization(doc.InnerXml, typeof(Monk));
                }
                else if (doc.InnerXml.Contains("</WitchDoctor>"))
                {
                    _classes = (Classes)XmlSerializable.Deserialization(doc.InnerXml, typeof(WitchDoctor));
                }
                else if (doc.InnerXml.Contains("</DemonHunter>"))
                {
                    _classes = (Classes)XmlSerializable.Deserialization(doc.InnerXml, typeof(DemonHunter));
                }
                else
                {
                    MessageBox.Show("文件格式错误！");
                    return;
                }

                LoadItemsControls();
                RefreshClassesData();
            }
        }

        private void LoadItemsControls()
        {
            itemsAmuletsLeft.Items = _classes.ClassesItems[ItemsType.AmuletsLeft];
            itemsAmuletsLeft.Refresh();
            itemsAmuletsRight.Items = _classes.ClassesItems[ItemsType.AmuletsRight];
            itemsAmuletsRight.Refresh();
            itemsFeet.Items = _classes.ClassesItems[ItemsType.Feet];
            itemsFeet.Refresh();
            itemsHands.Items = _classes.ClassesItems[ItemsType.Hands];
            itemsHands.Refresh();
            itemsHead.Items = _classes.ClassesItems[ItemsType.Head];
            itemsHead.Refresh();
            itemsOffHand.Items = _classes.ClassesItems[ItemsType.OffHand];
            itemsOffHand.Refresh();
            itemsRings.Items = _classes.ClassesItems[ItemsType.Rings];
            itemsRings.Refresh();
            itemsShoulders.Items = _classes.ClassesItems[ItemsType.Shoulders];
            itemsShoulders.Refresh();
            itemsTorso.Items = _classes.ClassesItems[ItemsType.Torso];
            itemsTorso.Refresh();
            itemsWaist.Items = _classes.ClassesItems[ItemsType.Waist];
            itemsWaist.Refresh();
            itemsWeapons.Items = _classes.ClassesItems[ItemsType.Weapons];
            itemsWeapons.Refresh();
            itemsWrists.Items = _classes.ClassesItems[ItemsType.Wrists];
            itemsWrists.Refresh();
            itemsLegs.Items = _classes.ClassesItems[ItemsType.Legs];
            itemsLegs.Refresh();
        }

        private void menuNew_Click(object sender, EventArgs e)
        {
            NewClasses newWindow = new NewClasses();
            if (newWindow.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                CreateNewClasses(newWindow.ClassesType);
            }
        }

        private void CreateNewClasses(String classesType)
        {
            switch (classesType)
            {
                case "Barbarian":
                    _classes = new Barbarian();
                    break;
                case "Wizard":
                    _classes = new Wizard();
                    break;
                case "Monk":
                    _classes = new Monk();
                    break;
                case "WitchDoctor":
                    _classes = new WitchDoctor();
                    break;
                case "DemonHunter":
                    _classes = new DemonHunter();
                    break;
                default:
                    return;
            }
            itemsAmuletsLeft.Items = new Items(ItemsType.AmuletsLeft);
            _classes.ClassesItems.Add(ItemsType.AmuletsLeft, itemsAmuletsLeft.Items);
            itemsAmuletsLeft.Refresh();
            itemsAmuletsRight.Items = new Items(ItemsType.AmuletsRight);
            _classes.ClassesItems.Add(ItemsType.AmuletsRight, itemsAmuletsRight.Items);
            itemsAmuletsRight.Refresh();
            itemsFeet.Items = new Items(ItemsType.Feet);
            _classes.ClassesItems.Add(ItemsType.Feet, itemsFeet.Items);
            itemsFeet.Refresh();
            itemsHands.Items = new Items(ItemsType.Hands);
            _classes.ClassesItems.Add(ItemsType.Hands, itemsHands.Items);
            itemsHands.Refresh();
            itemsHead.Items = new Items(ItemsType.Head);
            _classes.ClassesItems.Add(ItemsType.Head, itemsHead.Items);
            itemsHead.Refresh();
            itemsOffHand.Items = new Items(ItemsType.OffHand);
            _classes.ClassesItems.Add(ItemsType.OffHand, itemsOffHand.Items);
            itemsOffHand.Refresh();
            itemsRings.Items = new Items(ItemsType.Rings);
            _classes.ClassesItems.Add(ItemsType.Rings, itemsRings.Items);
            itemsRings.Refresh();
            itemsShoulders.Items = new Items(ItemsType.Shoulders);
            _classes.ClassesItems.Add(ItemsType.Shoulders, itemsShoulders.Items);
            itemsShoulders.Refresh();
            itemsTorso.Items = new Items(ItemsType.Torso);
            _classes.ClassesItems.Add(ItemsType.Torso, itemsTorso.Items);
            itemsTorso.Refresh();
            itemsWaist.Items = new Items(ItemsType.Waist);
            _classes.ClassesItems.Add(ItemsType.Waist, itemsWaist.Items);
            itemsWaist.Refresh();
            itemsWeapons.Items = new Items(ItemsType.Weapons);
            _classes.ClassesItems.Add(ItemsType.Weapons, itemsWeapons.Items);
            itemsWeapons.Refresh();
            itemsWrists.Items = new Items(ItemsType.Wrists);
            _classes.ClassesItems.Add(ItemsType.Wrists, itemsWrists.Items);
            itemsWrists.Refresh();
            itemsLegs.Items = new Items(ItemsType.Legs);
            _classes.ClassesItems.Add(ItemsType.Legs, itemsLegs.Items);
            itemsLegs.Refresh();

            RefreshClassesData();
        }

        private void RefreshItemsAData()
        {
            if (_itemsA == null)
            {
                lblAArmor.ForeColor = Color.Black;
                lblAArmor.Text = "护甲";
                lblALife.ForeColor = Color.Black;
                lblALife.Text = "生命值";
                lblADamageReductionByArmor.ForeColor = Color.Black;
                lblADamageReductionByArmor.Text = "护甲减伤";
                lblADamageReductionByRestance.ForeColor = Color.Black;
                lblADamageReductionByRestance.Text = "抗性减伤";
                lblATotalDamageReduction.ForeColor = Color.Black;
                lblATotalDamageReduction.Text = "总减伤";
                lblAEffectiveLife.ForeColor = Color.Black;
                lblAEffectiveLife.Text = "有效生命值";
                lblADamage.ForeColor = Color.Black;
                lblADamage.Text = "面板伤害";
                lblALifePerHit.ForeColor = Color.Black;
                lblALifePerHit.Text = "击中恢复";
                lblALifePerKill.ForeColor = Color.Black;
                lblALifePerKill.Text = "击杀恢复";
                lblALifePerSecond.ForeColor = Color.Black;
                lblALifePerSecond.Text = "每秒恢复";
                lblALifeSteal.ForeColor = Color.Black;
                lblALifeSteal.Text = "生命汲取";
                return;
            }

            Classes classesA = _classes.Clone();
            classesA.ClassesItems[_itemsA.ItemsType] = _itemsA;

            //护甲
            if (classesA.Armor > _classes.Armor)
            {
                lblAArmor.ForeColor = Color.Green;
                lblAArmor.Text = String.Format("护甲       +{0}", classesA.Armor - _classes.Armor);
            }
            else if (classesA.Armor < _classes.Armor)
            {
                lblAArmor.ForeColor = Color.Red;
                lblAArmor.Text = String.Format("护甲       -{0}", _classes.Armor - classesA.Armor);
            }
            else
            {
                lblAArmor.ForeColor = Color.Black;
                lblAArmor.Text = String.Format("护甲       +{0}", 0);
            }

            //生命值
            if (classesA.Life > _classes.Life)
            {
                lblALife.ForeColor = Color.Green;
                lblALife.Text = String.Format("生命值     +{0}", classesA.Life - _classes.Life);
            }
            else if (classesA.Life < _classes.Life)
            {
                lblALife.ForeColor = Color.Red;
                lblALife.Text = String.Format("生命值     -{0}", _classes.Life - classesA.Life);
            }
            else
            {
                lblALife.ForeColor = Color.Black;
                lblALife.Text = String.Format("生命值     +{0}", 0);
            }

            //护甲减伤
            if (classesA.DamageReductionByArmor > _classes.DamageReductionByArmor)
            {
                lblADamageReductionByArmor.ForeColor = Color.Green;
                lblADamageReductionByArmor.Text = String.Format("护甲减伤   +{0}", (classesA.DamageReductionByArmor - _classes.DamageReductionByArmor).ToString("F2"));
            }
            else if (classesA.DamageReductionByArmor < _classes.DamageReductionByArmor)
            {
                lblADamageReductionByArmor.ForeColor = Color.Red;
                lblADamageReductionByArmor.Text = String.Format("护甲减伤   -{0}", (_classes.DamageReductionByArmor - classesA.DamageReductionByArmor).ToString("F2"));
            }
            else
            {
                lblADamageReductionByArmor.ForeColor = Color.Black;
                lblADamageReductionByArmor.Text = String.Format("护甲减伤   +{0}", 0);
            }

            //抗性减伤
            if (classesA.DamageReductionByResistance > _classes.DamageReductionByResistance)
            {
                lblADamageReductionByRestance.ForeColor = Color.Green;
                lblADamageReductionByRestance.Text = String.Format("抗性减伤   +{0}", (classesA.DamageReductionByResistance - _classes.DamageReductionByResistance).ToString("F2"));
            }
            else if (classesA.DamageReductionByResistance < _classes.DamageReductionByResistance)
            {
                lblADamageReductionByRestance.ForeColor = Color.Red;
                lblADamageReductionByRestance.Text = String.Format("抗性减伤   -{0}", (_classes.DamageReductionByResistance - classesA.DamageReductionByResistance).ToString("F2"));
            }
            else
            {
                lblADamageReductionByRestance.ForeColor = Color.Black;
                lblADamageReductionByRestance.Text = String.Format("抗性减伤   +{0}", 0);
            }

            //总减伤
            if (classesA.TotalDamageReduction > _classes.TotalDamageReduction)
            {
                lblATotalDamageReduction.ForeColor = Color.Green;
                lblATotalDamageReduction.Text = String.Format("总减伤     +{0}", (classesA.TotalDamageReduction - _classes.TotalDamageReduction).ToString("F2"));
            }
            else if (classesA.TotalDamageReduction < _classes.TotalDamageReduction)
            {
                lblATotalDamageReduction.ForeColor = Color.Red;
                lblATotalDamageReduction.Text = String.Format("总减伤     -{0}", (_classes.TotalDamageReduction - classesA.TotalDamageReduction).ToString("F2"));
            }
            else
            {
                lblATotalDamageReduction.ForeColor = Color.Black;
                lblATotalDamageReduction.Text = String.Format("总减伤     +{0}", 0);
            }

            //有效生命值
            if (classesA.EffectiveLife > _classes.EffectiveLife)
            {
                lblAEffectiveLife.ForeColor = Color.Green;
                lblAEffectiveLife.Text = String.Format("有效生命值 +{0}", (classesA.EffectiveLife - _classes.EffectiveLife).ToString("F2"));
            }
            else if (classesA.EffectiveLife < _classes.EffectiveLife)
            {
                lblAEffectiveLife.ForeColor = Color.Red;
                lblAEffectiveLife.Text = String.Format("有效生命值 -{0}", (_classes.EffectiveLife - classesA.EffectiveLife).ToString("F2"));
            }
            else
            {
                lblAEffectiveLife.ForeColor = Color.Black;
                lblAEffectiveLife.Text = String.Format("有效生命值 +{0}", 0);
            }

            //面板伤害
            if (classesA.Damage > _classes.Damage)
            {
                lblADamage.ForeColor = Color.Green;
                lblADamage.Text = String.Format("面板伤害   +{0}", (classesA.Damage - _classes.Damage).ToString("F2"));
            }
            else if (classesA.Damage < _classes.Damage)
            {
                lblADamage.ForeColor = Color.Red;
                lblADamage.Text = String.Format("面板伤害   -{0}", (_classes.Damage - classesA.Damage).ToString("F2"));
            }
            else
            {
                lblADamage.ForeColor = Color.Black;
                lblADamage.Text = String.Format("面板伤害   +{0}", 0);
            }

            //击中恢复
            if (classesA.LifePerHit > _classes.LifePerHit)
            {
                lblALifePerHit.ForeColor = Color.Green;
                lblALifePerHit.Text = String.Format("击中恢复   +{0}", classesA.LifePerHit - _classes.LifePerHit);
            }
            else if (classesA.LifePerHit < _classes.LifePerHit)
            {
                lblALifePerHit.ForeColor = Color.Red;
                lblALifePerHit.Text = String.Format("击中恢复   -{0}", _classes.LifePerHit - classesA.LifePerHit);
            }
            else
            {
                lblALifePerHit.ForeColor = Color.Black;
                lblALifePerHit.Text = String.Format("击中恢复   +{0}", 0);
            }

            //击杀恢复
            if (classesA.LifePerKill > _classes.LifePerKill)
            {
                lblALifePerKill.ForeColor = Color.Green;
                lblALifePerKill.Text = String.Format("击杀恢复   +{0}", classesA.LifePerKill - _classes.LifePerKill);
            }
            else if (classesA.LifePerKill < _classes.LifePerKill)
            {
                lblALifePerKill.ForeColor = Color.Red;
                lblALifePerKill.Text = String.Format("击杀恢复   -{0}", _classes.LifePerKill - classesA.LifePerKill);
            }
            else
            {
                lblALifePerKill.ForeColor = Color.Black;
                lblALifePerKill.Text = String.Format("击杀恢复   +{0}", 0);
            }

            //每秒恢复
            if (classesA.LifePerSecond > _classes.LifePerSecond)
            {
                lblALifePerSecond.ForeColor = Color.Green;
                lblALifePerSecond.Text = String.Format("每秒恢复   +{0}", classesA.LifePerSecond - _classes.LifePerSecond);
            }
            else if (classesA.LifePerSecond < _classes.LifePerSecond)
            {
                lblALifePerSecond.ForeColor = Color.Red;
                lblALifePerSecond.Text = String.Format("每秒恢复   -{0}", _classes.LifePerSecond - classesA.LifePerSecond);
            }
            else
            {
                lblALifePerSecond.ForeColor = Color.Black;
                lblALifePerSecond.Text = String.Format("每秒恢复   +{0}", 0);
            }

            //生命汲取
            if (classesA.LifeSteal > _classes.LifeSteal)
            {
                lblALifeSteal.ForeColor = Color.Green;
                lblALifeSteal.Text = String.Format("生命汲取   +{0}", (classesA.LifeSteal - _classes.LifeSteal).ToString("P"));
            }
            else if (classesA.LifeSteal < _classes.LifeSteal)
            {
                lblALifeSteal.ForeColor = Color.Red;
                lblALifeSteal.Text = String.Format("生命汲取   -{0}", (_classes.LifeSteal - classesA.LifeSteal).ToString("P"));
            }
            else
            {
                lblALifeSteal.ForeColor = Color.Black;
                lblALifeSteal.Text = String.Format("生命汲取   +{0}", 0);
            }
        }

        private void RefreshItemsBData()
        {
            if (_itemsB == null)
            {
                lblBArmor.ForeColor = Color.Black;
                lblBArmor.Text = "护甲";
                lblBLife.ForeColor = Color.Black;
                lblBLife.Text = "生命值";
                lblBDamageReductionByArmor.ForeColor = Color.Black;
                lblBDamageReductionByArmor.Text = "护甲减伤";
                lblBDamageReductionByRestance.ForeColor = Color.Black;
                lblBDamageReductionByRestance.Text = "抗性减伤";
                lblBTotalDamageReduction.ForeColor = Color.Black;
                lblBTotalDamageReduction.Text = "总减伤";
                lblBEffectiveLife.ForeColor = Color.Black;
                lblBEffectiveLife.Text = "有效生命值";
                lblBDamage.ForeColor = Color.Black;
                lblBDamage.Text = "面板伤害";
                lblBLifePerHit.ForeColor = Color.Black;
                lblBLifePerHit.Text = "击中恢复";
                lblBLifePerKill.ForeColor = Color.Black;
                lblBLifePerKill.Text = "击杀恢复";
                lblBLifePerSecond.ForeColor = Color.Black;
                lblBLifePerSecond.Text = "每秒恢复";
                lblBLifeSteal.ForeColor = Color.Black;
                lblBLifeSteal.Text = "生命汲取";
                return;
            }

            Classes classesB = _classes.Clone();
            classesB.ClassesItems[_itemsB.ItemsType] = _itemsB;

            //护甲
            if (classesB.Armor > _classes.Armor)
            {
                lblBArmor.ForeColor = Color.Green;
                lblBArmor.Text = String.Format("护甲       +{0}", classesB.Armor - _classes.Armor);
            }
            else if (classesB.Armor < _classes.Armor)
            {
                lblBArmor.ForeColor = Color.Red;
                lblBArmor.Text = String.Format("护甲       -{0}", _classes.Armor - classesB.Armor);
            }
            else
            {
                lblBArmor.ForeColor = Color.Black;
                lblBArmor.Text = String.Format("护甲       +{0}", 0);
            }

            //生命值
            if (classesB.Life > _classes.Life)
            {
                lblBLife.ForeColor = Color.Green;
                lblBLife.Text = String.Format("生命值     +{0}", classesB.Life - _classes.Life);
            }
            else if (classesB.Life < _classes.Life)
            {
                lblBLife.ForeColor = Color.Red;
                lblBLife.Text = String.Format("生命值     -{0}", _classes.Life - classesB.Life);
            }
            else
            {
                lblBLife.ForeColor = Color.Black;
                lblBLife.Text = String.Format("生命值     +{0}", 0);
            }

            //护甲减伤
            if (classesB.DamageReductionByArmor > _classes.DamageReductionByArmor)
            {
                lblBDamageReductionByArmor.ForeColor = Color.Green;
                lblBDamageReductionByArmor.Text = String.Format("护甲减伤   +{0}", (classesB.DamageReductionByArmor - _classes.DamageReductionByArmor).ToString("F2"));
            }
            else if (classesB.DamageReductionByArmor < _classes.DamageReductionByArmor)
            {
                lblBDamageReductionByArmor.ForeColor = Color.Red;
                lblBDamageReductionByArmor.Text = String.Format("护甲减伤   -{0}", (_classes.DamageReductionByArmor - classesB.DamageReductionByArmor).ToString("F2"));
            }
            else
            {
                lblBDamageReductionByArmor.ForeColor = Color.Black;
                lblBDamageReductionByArmor.Text = String.Format("护甲减伤   +{0}", 0);
            }

            //抗性减伤
            if (classesB.DamageReductionByResistance > _classes.DamageReductionByResistance)
            {
                lblBDamageReductionByRestance.ForeColor = Color.Green;
                lblBDamageReductionByRestance.Text = String.Format("抗性减伤   +{0}", (classesB.DamageReductionByResistance - _classes.DamageReductionByResistance).ToString("F2"));
            }
            else if (classesB.DamageReductionByResistance < _classes.DamageReductionByResistance)
            {
                lblBDamageReductionByRestance.ForeColor = Color.Red;
                lblBDamageReductionByRestance.Text = String.Format("抗性减伤   -{0}", (_classes.DamageReductionByResistance - classesB.DamageReductionByResistance).ToString("F2"));
            }
            else
            {
                lblBDamageReductionByRestance.ForeColor = Color.Black;
                lblBDamageReductionByRestance.Text = String.Format("抗性减伤   +{0}", 0);
            }

            //总减伤
            if (classesB.TotalDamageReduction > _classes.TotalDamageReduction)
            {
                lblBTotalDamageReduction.ForeColor = Color.Green;
                lblBTotalDamageReduction.Text = String.Format("总减伤     +{0}", (classesB.TotalDamageReduction - _classes.TotalDamageReduction).ToString("F2"));
            }
            else if (classesB.TotalDamageReduction < _classes.TotalDamageReduction)
            {
                lblBTotalDamageReduction.ForeColor = Color.Red;
                lblBTotalDamageReduction.Text = String.Format("总减伤     -{0}", (_classes.TotalDamageReduction - classesB.TotalDamageReduction).ToString("F2"));
            }
            else
            {
                lblBTotalDamageReduction.ForeColor = Color.Black;
                lblBTotalDamageReduction.Text = String.Format("总减伤     +{0}", 0);
            }

            //有效生命值
            if (classesB.EffectiveLife > _classes.EffectiveLife)
            {
                lblBEffectiveLife.ForeColor = Color.Green;
                lblBEffectiveLife.Text = String.Format("有效生命值 +{0}", (classesB.EffectiveLife - _classes.EffectiveLife).ToString("F2"));
            }
            else if (classesB.EffectiveLife < _classes.EffectiveLife)
            {
                lblBEffectiveLife.ForeColor = Color.Red;
                lblBEffectiveLife.Text = String.Format("有效生命值 -{0}", (_classes.EffectiveLife - classesB.EffectiveLife).ToString("F2"));
            }
            else
            {
                lblBEffectiveLife.ForeColor = Color.Black;
                lblBEffectiveLife.Text = String.Format("有效生命值 +{0}", 0);
            }

            //面板伤害
            if (classesB.Damage > _classes.Damage)
            {
                lblBDamage.ForeColor = Color.Green;
                lblBDamage.Text = String.Format("面板伤害   +{0}", (classesB.Damage - _classes.Damage).ToString("F2"));
            }
            else if (classesB.Damage < _classes.Damage)
            {
                lblBDamage.ForeColor = Color.Red;
                lblBDamage.Text = String.Format("面板伤害   -{0}", (_classes.Damage - classesB.Damage).ToString("F2"));
            }
            else
            {
                lblBDamage.ForeColor = Color.Black;
                lblBDamage.Text = String.Format("面板伤害   +{0}", 0);
            }

            //击中恢复
            if (classesB.LifePerHit > _classes.LifePerHit)
            {
                lblBLifePerHit.ForeColor = Color.Green;
                lblBLifePerHit.Text = String.Format("击中恢复   +{0}", classesB.LifePerHit - _classes.LifePerHit);
            }
            else if (classesB.LifePerHit < _classes.LifePerHit)
            {
                lblBLifePerHit.ForeColor = Color.Red;
                lblBLifePerHit.Text = String.Format("击中恢复   -{0}", _classes.LifePerHit - classesB.LifePerHit);
            }
            else
            {
                lblBLifePerHit.ForeColor = Color.Black;
                lblBLifePerHit.Text = String.Format("击中恢复   +{0}", 0);
            }

            //击杀恢复
            if (classesB.LifePerKill > _classes.LifePerKill)
            {
                lblBLifePerKill.ForeColor = Color.Green;
                lblBLifePerKill.Text = String.Format("击杀恢复   +{0}", classesB.LifePerKill - _classes.LifePerKill);
            }
            else if (classesB.LifePerKill < _classes.LifePerKill)
            {
                lblBLifePerKill.ForeColor = Color.Red;
                lblBLifePerKill.Text = String.Format("击杀恢复   -{0}", _classes.LifePerKill - classesB.LifePerKill);
            }
            else
            {
                lblBLifePerKill.ForeColor = Color.Black;
                lblBLifePerKill.Text = String.Format("击杀恢复   +{0}", 0);
            }

            //每秒恢复
            if (classesB.LifePerSecond > _classes.LifePerSecond)
            {
                lblBLifePerSecond.ForeColor = Color.Green;
                lblBLifePerSecond.Text = String.Format("每秒恢复   +{0}", classesB.LifePerSecond - _classes.LifePerSecond);
            }
            else if (classesB.LifePerSecond < _classes.LifePerSecond)
            {
                lblBLifePerSecond.ForeColor = Color.Red;
                lblBLifePerSecond.Text = String.Format("每秒恢复   -{0}", _classes.LifePerSecond - classesB.LifePerSecond);
            }
            else
            {
                lblBLifePerSecond.ForeColor = Color.Black;
                lblBLifePerSecond.Text = String.Format("每秒恢复   +{0}", 0);
            }

            //生命汲取
            if (classesB.LifeSteal > _classes.LifeSteal)
            {
                lblBLifeSteal.ForeColor = Color.Green;
                lblBLifeSteal.Text = String.Format("生命汲取   +{0}", (classesB.LifeSteal - _classes.LifeSteal).ToString("P"));
            }
            else if (classesB.LifeSteal < _classes.LifeSteal)
            {
                lblBLifeSteal.ForeColor = Color.Red;
                lblBLifeSteal.Text = String.Format("生命汲取   -{0}", (_classes.LifeSteal - classesB.LifeSteal).ToString("P"));
            }
            else
            {
                lblBLifeSteal.ForeColor = Color.Black;
                lblBLifeSteal.Text = String.Format("生命汲取   +{0}", 0);
            }
        }

        private void RefreshItemsCData()
        {
            if (_itemsC == null)
            {
                lblCArmor.ForeColor = Color.Black;
                lblCArmor.Text = "护甲";
                lblCLife.ForeColor = Color.Black;
                lblCLife.Text = "生命值";
                lblCDamageReductionByArmor.ForeColor = Color.Black;
                lblCDamageReductionByArmor.Text = "护甲减伤";
                lblCDamageReductionByRestance.ForeColor = Color.Black;
                lblCDamageReductionByRestance.Text = "抗性减伤";
                lblCTotalDamageReduction.ForeColor = Color.Black;
                lblCTotalDamageReduction.Text = "总减伤";
                lblCEffectiveLife.ForeColor = Color.Black;
                lblCEffectiveLife.Text = "有效生命值";
                lblCDamage.ForeColor = Color.Black;
                lblCDamage.Text = "面板伤害";
                lblCLifePerHit.ForeColor = Color.Black;
                lblCLifePerHit.Text = "击中恢复";
                lblCLifePerKill.ForeColor = Color.Black;
                lblCLifePerKill.Text = "击杀恢复";
                lblCLifePerSecond.ForeColor = Color.Black;
                lblCLifePerSecond.Text = "每秒恢复";
                lblCLifeSteal.ForeColor = Color.Black;
                lblCLifeSteal.Text = "生命汲取";
                return;
            }

            Classes classesC = _classes.Clone();
            classesC.ClassesItems[_itemsC.ItemsType] = _itemsC;

            //护甲
            if (classesC.Armor > _classes.Armor)
            {
                lblCArmor.ForeColor = Color.Green;
                lblCArmor.Text = String.Format("护甲       +{0}", classesC.Armor - _classes.Armor);
            }
            else if (classesC.Armor < _classes.Armor)
            {
                lblCArmor.ForeColor = Color.Red;
                lblCArmor.Text = String.Format("护甲       -{0}", _classes.Armor - classesC.Armor);
            }
            else
            {
                lblCArmor.ForeColor = Color.Black;
                lblCArmor.Text = String.Format("护甲       +{0}", 0);
            }

            //生命值
            if (classesC.Life > _classes.Life)
            {
                lblCLife.ForeColor = Color.Green;
                lblCLife.Text = String.Format("生命值     +{0}", classesC.Life - _classes.Life);
            }
            else if (classesC.Life < _classes.Life)
            {
                lblCLife.ForeColor = Color.Red;
                lblCLife.Text = String.Format("生命值     -{0}", _classes.Life - classesC.Life);
            }
            else
            {
                lblCLife.ForeColor = Color.Black;
                lblCLife.Text = String.Format("生命值     +{0}", 0);
            }

            //护甲减伤
            if (classesC.DamageReductionByArmor > _classes.DamageReductionByArmor)
            {
                lblCDamageReductionByArmor.ForeColor = Color.Green;
                lblCDamageReductionByArmor.Text = String.Format("护甲减伤   +{0}", (classesC.DamageReductionByArmor - _classes.DamageReductionByArmor).ToString("F2"));
            }
            else if (classesC.DamageReductionByArmor < _classes.DamageReductionByArmor)
            {
                lblCDamageReductionByArmor.ForeColor = Color.Red;
                lblCDamageReductionByArmor.Text = String.Format("护甲减伤   -{0}", (_classes.DamageReductionByArmor - classesC.DamageReductionByArmor).ToString("F2"));
            }
            else
            {
                lblCDamageReductionByArmor.ForeColor = Color.Black;
                lblCDamageReductionByArmor.Text = String.Format("护甲减伤   +{0}", 0);
            }

            //抗性减伤
            if (classesC.DamageReductionByResistance > _classes.DamageReductionByResistance)
            {
                lblCDamageReductionByRestance.ForeColor = Color.Green;
                lblCDamageReductionByRestance.Text = String.Format("抗性减伤   +{0}", (classesC.DamageReductionByResistance - _classes.DamageReductionByResistance).ToString("F2"));
            }
            else if (classesC.DamageReductionByResistance < _classes.DamageReductionByResistance)
            {
                lblCDamageReductionByRestance.ForeColor = Color.Red;
                lblCDamageReductionByRestance.Text = String.Format("抗性减伤   -{0}", (_classes.DamageReductionByResistance - classesC.DamageReductionByResistance).ToString("F2"));
            }
            else
            {
                lblCDamageReductionByRestance.ForeColor = Color.Black;
                lblCDamageReductionByRestance.Text = String.Format("抗性减伤   +{0}", 0);
            }

            //总减伤
            if (classesC.TotalDamageReduction > _classes.TotalDamageReduction)
            {
                lblCTotalDamageReduction.ForeColor = Color.Green;
                lblCTotalDamageReduction.Text = String.Format("总减伤     +{0}", (classesC.TotalDamageReduction - _classes.TotalDamageReduction).ToString("F2"));
            }
            else if (classesC.TotalDamageReduction < _classes.TotalDamageReduction)
            {
                lblCTotalDamageReduction.ForeColor = Color.Red;
                lblCTotalDamageReduction.Text = String.Format("总减伤     -{0}", (_classes.TotalDamageReduction - classesC.TotalDamageReduction).ToString("F2"));
            }
            else
            {
                lblCTotalDamageReduction.ForeColor = Color.Black;
                lblCTotalDamageReduction.Text = String.Format("总减伤     +{0}", 0);
            }

            //有效生命值
            if (classesC.EffectiveLife > _classes.EffectiveLife)
            {
                lblCEffectiveLife.ForeColor = Color.Green;
                lblCEffectiveLife.Text = String.Format("有效生命值 +{0}", (classesC.EffectiveLife - _classes.EffectiveLife).ToString("F2"));
            }
            else if (classesC.EffectiveLife < _classes.EffectiveLife)
            {
                lblCEffectiveLife.ForeColor = Color.Red;
                lblCEffectiveLife.Text = String.Format("有效生命值 -{0}", (_classes.EffectiveLife - classesC.EffectiveLife).ToString("F2"));
            }
            else
            {
                lblCEffectiveLife.ForeColor = Color.Black;
                lblCEffectiveLife.Text = String.Format("有效生命值 +{0}", 0);
            }

            //面板伤害
            if (classesC.Damage > _classes.Damage)
            {
                lblCDamage.ForeColor = Color.Green;
                lblCDamage.Text = String.Format("面板伤害   +{0}", (classesC.Damage - _classes.Damage).ToString("F2"));
            }
            else if (classesC.Damage < _classes.Damage)
            {
                lblCDamage.ForeColor = Color.Red;
                lblCDamage.Text = String.Format("面板伤害   -{0}", (_classes.Damage - classesC.Damage).ToString("F2"));
            }
            else
            {
                lblCDamage.ForeColor = Color.Black;
                lblCDamage.Text = String.Format("面板伤害   +{0}", 0);
            }

            //击中恢复
            if (classesC.LifePerHit > _classes.LifePerHit)
            {
                lblCLifePerHit.ForeColor = Color.Green;
                lblCLifePerHit.Text = String.Format("击中恢复   +{0}", classesC.LifePerHit - _classes.LifePerHit);
            }
            else if (classesC.LifePerHit < _classes.LifePerHit)
            {
                lblCLifePerHit.ForeColor = Color.Red;
                lblCLifePerHit.Text = String.Format("击中恢复   -{0}", _classes.LifePerHit - classesC.LifePerHit);
            }
            else
            {
                lblCLifePerHit.ForeColor = Color.Black;
                lblCLifePerHit.Text = String.Format("击中恢复   +{0}", 0);
            }

            //击杀恢复
            if (classesC.LifePerKill > _classes.LifePerKill)
            {
                lblCLifePerKill.ForeColor = Color.Green;
                lblCLifePerKill.Text = String.Format("击杀恢复   +{0}", classesC.LifePerKill - _classes.LifePerKill);
            }
            else if (classesC.LifePerKill < _classes.LifePerKill)
            {
                lblCLifePerKill.ForeColor = Color.Red;
                lblCLifePerKill.Text = String.Format("击杀恢复   -{0}", _classes.LifePerKill - classesC.LifePerKill);
            }
            else
            {
                lblCLifePerKill.ForeColor = Color.Black;
                lblCLifePerKill.Text = String.Format("击杀恢复   +{0}", 0);
            }

            //每秒恢复
            if (classesC.LifePerSecond > _classes.LifePerSecond)
            {
                lblCLifePerSecond.ForeColor = Color.Green;
                lblCLifePerSecond.Text = String.Format("每秒恢复   +{0}", classesC.LifePerSecond - _classes.LifePerSecond);
            }
            else if (classesC.LifePerSecond < _classes.LifePerSecond)
            {
                lblCLifePerSecond.ForeColor = Color.Red;
                lblCLifePerSecond.Text = String.Format("每秒恢复   -{0}", _classes.LifePerSecond - classesC.LifePerSecond);
            }
            else
            {
                lblCLifePerSecond.ForeColor = Color.Black;
                lblCLifePerSecond.Text = String.Format("每秒恢复   +{0}", 0);
            }

            //生命汲取
            if (classesC.LifeSteal > _classes.LifeSteal)
            {
                lblCLifeSteal.ForeColor = Color.Green;
                lblCLifeSteal.Text = String.Format("生命汲取   +{0}", (classesC.LifeSteal - _classes.LifeSteal).ToString("P"));
            }
            else if (classesC.LifeSteal < _classes.LifeSteal)
            {
                lblCLifeSteal.ForeColor = Color.Red;
                lblCLifeSteal.Text = String.Format("生命汲取   -{0}", (_classes.LifeSteal - classesC.LifeSteal).ToString("P"));
            }
            else
            {
                lblCLifeSteal.ForeColor = Color.Black;
                lblCLifeSteal.Text = String.Format("生命汲取   +{0}", 0);
            }
        }

        private void itemsA_MouseClick(object sender, MouseEventArgs e)
        {
            if (_itemsA == null)
            {
                NewItems itemsWindow = new NewItems();
                if (itemsWindow.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    _itemsA = new Items(itemsWindow.ItemsType);
                }
            }

            if (_itemsA != null)
            {
                SelectProperty selectWindow = new SelectProperty(_itemsA);
                if (selectWindow.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    _itemsA = selectWindow.Items;
                }
            }

            itemsA.Items = _itemsA;
            itemsA.Refresh();
            RefreshItemsAData();
        }

        private void btnAChange_Click(object sender, EventArgs e)
        {
            Items temp = _classes.ClassesItems[_itemsA.ItemsType];
            _classes.ClassesItems[_itemsA.ItemsType] = _itemsA;
            _itemsA = temp;

            itemsA.Items = _itemsA;
            LoadItemsControls();
            itemsA.Refresh();
            RefreshClassesData();
        }

        private void btnADelete_Click(object sender, EventArgs e)
        {
            _itemsA = null;
            itemsA.Items = null;
            itemsA.Refresh();
            RefreshItemsAData();
        }

        private void itemsB_MouseClick(object sender, MouseEventArgs e)
        {
            if (_itemsB == null)
            {
                NewItems itemsWindow = new NewItems();
                if (itemsWindow.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    _itemsB = new Items(itemsWindow.ItemsType);
                }
            }

            if (_itemsB != null)
            {
                SelectProperty selectWindow = new SelectProperty(_itemsB);
                if (selectWindow.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    _itemsB = selectWindow.Items;
                }
            }

            itemsB.Items = _itemsB;
            itemsB.Refresh();
            RefreshItemsBData();
        }

        private void btnBChange_Click(object sender, EventArgs e)
        {
            Items temp = _classes.ClassesItems[_itemsB.ItemsType];
            _classes.ClassesItems[_itemsB.ItemsType] = _itemsB;
            _itemsB = temp;

            itemsB.Items = _itemsB;
            LoadItemsControls();
            itemsB.Refresh();
            RefreshClassesData();
        }

        private void btnBDelete_Click(object sender, EventArgs e)
        {
            _itemsB = null;
            itemsB.Items = null;
            itemsB.Refresh();
            RefreshItemsAData();
        }

        private void itemsC_MouseClick(object sender, MouseEventArgs e)
        {
            if (_itemsC == null)
            {
                NewItems itemsWindow = new NewItems();
                if (itemsWindow.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    _itemsC = new Items(itemsWindow.ItemsType);
                }
            }

            if (_itemsC != null)
            {
                SelectProperty selectWindow = new SelectProperty(_itemsC);
                if (selectWindow.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    _itemsC = selectWindow.Items;
                }
            }

            itemsC.Items = _itemsC;
            itemsC.Refresh();
            RefreshItemsCData();
        }

        private void btnCChange_Click(object sender, EventArgs e)
        {
            Items temp = _classes.ClassesItems[_itemsC.ItemsType];
            _classes.ClassesItems[_itemsC.ItemsType] = _itemsC;
            _itemsC = temp;

            itemsC.Items = _itemsC;
            LoadItemsControls();
            itemsC.Refresh();
            RefreshClassesData();
        }

        private void btnCDelete_Click(object sender, EventArgs e)
        {
            _itemsC = null;
            itemsC.Items = null;
            itemsC.Refresh();
            RefreshItemsAData();
        }
    }
}
